﻿//Copyright (c) 2009-2010, Andreas Grünwald
//All rights reserved.

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

namespace yaTDL.Core
{
    /// <summary>
    /// A Project is a set of Tasks with some additional properties.
    /// </summary>       
    public class Project:ObjectWithId
    {
        #region Fields

        private string _name = "";
        private string _color = "";

        #endregion

        #region Properties
        
        /// <summary>
        /// The name of the Project.
        /// </summary>
        public string Name
        { 
            get { return _name; }
            set
            {
                if (_name != value)
                {
                    _name = value;
                    RaisePropertyChanged("Name");
                }
            }
        }

        public string Color
        { 
            get { return _color; }
            set
            {
                if (value != _color)
                {                    
                    _color = value;
                    RaisePropertyChanged("Color");
                }
            }
        }

        #endregion


        #region Contructor(s)

        /// <summary>
        /// Initialzies a new instance of Project
        /// </summary>
        /// <param name="Name">The Name of the new Project</param>
        public Project(string name):base("l_p_")
        {            
            this.Name = name;                                   
            Color = "";
        }

        /// <summary>
        /// Initialzies a new instance of Project
        /// </summary>
        public Project()           
            : this("")
        {           
        }

        #endregion


        #region Public Methods

        public Collection<PropertyChange> Diff(Project otherProject)
        {
            Collection<PropertyChange> result = base.Diff(otherProject);

            if (this.Name != otherProject.Name)
            { result.Add(new PropertyChange() { PropertyName = "Name", Value1 = this.Name, Value2 = otherProject.Name }); }

            if (this.Color != otherProject.Color)
            { result.Add(new PropertyChange() { PropertyName = "Color", Value1 = this.Color, Value2 = otherProject.Color }); }


            return result;
        }

        public override string ToString()
        {
            string result = "Project - ";
            result += "Name: " + Name + " - ";
            result += "Color: " + Color + " - ";
            result += base.ToString();
            return result;
        }

        public string ToShortString()
        {
            return String.Format("Project: {0}, Id:{1}", this.Name, this.Id);
        }


        public void ApplyProperties(Project otherProject)
        {
            this.Collapsed = otherProject.Collapsed;
            this.Indent = otherProject.Indent;
            this.Order = otherProject.Order;
            this.UserId = otherProject.UserId;
            this.Name = otherProject.Name;
            this.Color = otherProject.Color;
        }

        #endregion
    }
}



 